<template>
    <rx-dialog @handOk="onOk" @cancel="onCancel" :showok="!allowEdit" :showcancel="!allowEdit">
        <rx-fit>
            <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                <div class="table-operator">
                    <a-button v-if="allowEdit" type="primary" icon="plus" @click="addPrint">
                        {{ $ti18('rxList.addBtn', "新建") }}
                    </a-button>
                    <a-dropdown v-if="allowEdit && removeEnable && selectedRowKeys.length > 0">
                        <a-button type="danger" icon="delete" @click="delByIds(selectedRowKeys)">
                            {{ $ti18('rxList.delBtn', "删除") }}
                        </a-button>
                    </a-dropdown>
                </div>
                <span class="search-btn-box">
                    <span class="search-btn" @click="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
                </span>
            </div>
            <div slot="searchbar" btnalign="right" v-if="fitSearch" @search="search" @cancel="resetSearchList" @close="close">
                <a-form-item :label="i18n('form.templateName','模板名称')">
                    <a-input :placeholder="i18n('form.templateName','模板名称','input')"
                             v-model="queryParam['Q_a.NAME__S_LK']"/>
                </a-form-item>
            </div>
            <rx-grid
                ref="table"
                :allowRowSelect="!allowEdit"
                :multiSelect="false"
                :columns="columns"
                :defaultPageSize="10"
                url="/api-form/form/core/formPdfTemplate/query"
                :queryParam="queryParam"
                data-field="result.data"
                :pageSizeOptions="['10','30','40']"
                id-field="id"
                :selectRowKeys="selectRowKeys"
                @selectChange="onSelectChange"
            >
                <span slot="exportApp">
                    {{ exportI18n('export.isExport', '导出') }}
                    <a-tooltip placement="top">
                    <template slot="title">
                         <span>{{ exportI18n('export.helpInfo', '提示信息') }}</span>
                    </template>
                    <a-icon type="question-circle"/>
                    </a-tooltip>
                </span>
                <span slot="isExport" slot-scope="{ text, record }">
                    <a-tag :color="text == 1 ? 'green' : 'red'">
                        <span>{{ text == 1 ? exportI18n('export.yes', '是') : exportI18n('export.no', '否') }}</span>
                    </a-tag>
                </span>
                <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                    <span v-if="allowEdit && editEnable" @click.stop="editPrint(record)">
                        {{ $ti18('rxList.editBtn', "编辑") }}
                    </span>
                    <span v-if="allowEdit && removeEnable" @click.stop="delByIds([record.id])">
                        {{ $ti18('rxList.delBtn', "删除") }}
                    </span>
                    <span @click="setExport(record)">{{ record.isExport == 1 ? exportI18n('export.noExport', '不导出') : exportI18n('export.exported', '导出') }}</span>
                </span>
            </rx-grid>
        </rx-fit>
    </rx-dialog>
</template>

<script>
import FormPdfTemplateApi from "@/api/form/core/formPdfTemplate"
import FormPcPdfTemp from './FormPcPdfTemp'
import {BaseList, Util, RxFit} from "@lowcode/jpaas-common-lib";

export default {
    name: 'FormPdfTemplateList',
    components: {
        RxFit,
    },
    mixins: [BaseList],
    props: ["layerid", "destroy", "boDefId", "defId", "allowEdit"],
    data() {
        return {
            columns: [
                {
                    title: this.$ti18('rxList.index', '序号'),
                    type: 'indexColumn',
                    width: 100,
                    dataIndex: 'serial',
                    scopedSlots: {customRender: 'serial'}
                },
                {title: this.i18n('form.templateName', '模板名称'), dataIndex: 'name', width: 100},
                {title: this.i18n('form.createTime', '别名'), dataIndex: 'createTime', width: 100},
                {
                    dataIndex: 'isExport',
                    slots: {title: 'exportApp'},
                    width: 100,
                    scopedSlots: {customRender: 'isExport'}
                },
                {
                    title: this.$ti18('rxList.action', '操作'),
                    width: 100,
                    dataIndex: 'action',
                    scopedSlots: {customRender: 'action'}
                }
            ],
            selectRowKeys: [],
            component: FormPcPdfTemp,
            comment: this.i18n('list.comment', 'pdf模板'),
            widthHeight: ['800px', '600px'],
        }
    },
    created() {
        this.queryParam['Q_BO_DEF_ID__S_EQ'] = this.boDefId;
        if(this.defId){
          this.selectRowKeys.push(this.defId);
        }
    },
    mounted() {
      if(this.defId){
        this.$refs.table.selectRowKeys = [this.defId];
      }
    },
    methods: {
        i18n(name, text, key) {
            return this.$ti18(name, text, "pdfTemplate", key);
        },
        exportI18n(name, text, key) {
            return this.$ti18(name, text, "appExport", key);
        },
        // 设置是否导出
        setExport(record) {
            let self_ = this;
            let param = {
                id: record.id,
                isExport: record.isExport == 1 ? 0 : 1
            };
            FormPdfTemplateApi.update(param).then(res => {
                if (res.success) {
                    self_.$message.success(res.message);
                    self_.loadData();
                } else {
                    self_.$message.error(self_.exportI18n('export.settingFail', '设置失败！'));
                }
            });
        },
        resetSearchList() {
            this.$nextTick(() => {
                this.queryParam = {Q_BO_DEF_ID__S_EQ: this.boDefId};
                this.$nextTick(() => {
                    this.$refs[this.table].loadData();
                })
            })
        },
        delById(ids) {
            return FormPdfTemplateApi.del({ids: ids.join(',')});
        },
        getListByParams(parameter) {
            return FormPdfTemplateApi.query(parameter)
        },
        onOk() {
            var node = this.$refs.table.getSelectedRow();
            Util.closeWindow(this, 'ok', node);
        },
        onCancel() {
            Util.closeWindow(this, 'cancel');
        },
        addPrint() {
            var self_ = this;
            var baseConf = {
                curVm: self_,
                component: this.component,
                title: this.$ti18('rxList.newBtn', "添加") + this.comment,
                max: true,
                zIndex: 99,
                data: {boDefId: self_.boDefId}
            };
            Util.open(baseConf, function (action) {
                if (action == "ok") {
                    self_.refreshGrid();
                }
            });
        },
        editPrint(record) {
            var conf = {
                component: this.component,
                title: this.$ti18('rxList.editBtn', "编辑") + this.comment,
                max: true,
                data: {pkId: record.pkId, boDefId: this.boDefId}
            };
            this.handleEdit(conf);
        },
        editOnePrint() {
            var conf = {
                component: this.component,
                title: this.$ti18('rxList.editBtn', "编辑") + this.comment,
                max: true
            };
            if (this.selectedRows.length > 0) {
                conf.data = {pkId: this.selectedRows[0].pkId, boDefId: this.boDefId};
                this.handleEdit(conf)
            }
        }
    }
}
</script>
<style scoped>

</style>

